<?php

class Film extends CI_Model{

	private $filme = "filme";

	function get_results(){
		$result = array();
		$query = $this->db->get($this->filme);
		foreach ($query->result() as $row)
		{
    		array_push($result, $row);
		}
		return  $result;
	}

	function get_film($id){
		$data = array('ID' => $id);
		$this->db->where($data);
		$query = $this->db->get($this->filme);
		$row = $query->row();
		return $row;
	}

	function get_films($searched){
		$res = $this->get_results();
		$filme =  array();
		foreach ($res as $movie) {
			$movie = get_object_vars($movie);
			if(strpos($movie['titlu'], $searched) !== false)
				array_push($filme, $movie);
		}
		return $filme;
	}
	function get_filme_pt_ecran()
	{
		$res = $this->get_results();
		$filme = array();
		//var_dump($res);
		foreach ($res as $movie) {
			$movie = get_object_vars($movie);
			if($movie['ecran'] == 1){
				$f = array(
					'titlu' => $movie['titlu'],
					'descriere' => $movie['descriere'],
					'id' => $movie['id'],
					'poster' => $movie['poster']
					);
				array_push($filme, $f);
			}
		}
		return $filme;
	}
	function get_filme_pt_premiera()
	{
		$res = $this->get_results();
		$filme = array();

		foreach ($res as $movie) {
			$movie = get_object_vars($movie);
			if($movie['premiera'] == 1){
				$f['bg_premiera'] = $movie['bg_premiera'];
				array_push($filme, $f);
			}
		}
		return $filme;
	}
	function get_movies_on_days()
	{
		$res = $this->get_results();
		$orar = array();

		$luni = array();
		$marti = array();
		$miercuri = array();
		$joi = array();
		$vineri = array();
		$sambata = array();
		$duminica = array();

		foreach ($res as $movie)
		{
			$luni[] = $movie->orar_l;
			$marti[] = $movie->orar_ma;
			$miercuri[] = $movie->orar_mi;
			$joi[] = $movie->orar_j;
			$vineri[] = $movie->orar_v;
			$sambata[] = $movie->orar_s;
			$duminica[] = $movie->orar_d;
		}

		$orar['luni'] = $luni;
		$orar['marti'] = $marti;
		$orar['miercuri'] = $miercuri;
		$orar['joi'] = $joi;
		$orar['vineri'] = $vineri;
		$orar['sambata'] = $sambata;
		$orar['duminica'] = $duminica;

		return $orar;
	}

	function get_movie_program($id)
	{
		$movie = $this->get_film($id);
		$orar = array();
		$orar['luni'] = $movie->orar_l;
		$orar['marti'] = $movie->orar_ma;
		$orar['miercuri'] = $movie->orar_mi;
		$orar['joi'] = $movie->orar_j;
		$orar['vineri'] = $movie->orar_v;
		$orar['sambata'] = $movie->orar_s;
		$orar['duminica'] = $movie->orar_d;

		return $orar;
	}
}

?>